package com.example.meetingbook.controller;

import com.example.meetingbook.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author 麦健豪
 * @date 2021/12/24 18:13
 */
@Controller
@RequestMapping("/admin")
public class ApproveaccountController {
    public static final Integer PENDING_APPROVE = 0;

    @Autowired
    EmployeeService employeeService;

    /**
     * PENDING_APPROVE = 0 = status
     * status=0 待审批
     * 获取 待审批的员工列表 添加数据到emps供前端调用
     * return 注册审批页面
     * */
    @RequestMapping("/approveaccount")
    public String approveaccount(Model model) {
        model.addAttribute("emps", employeeService.getAllEmpsByStatus(PENDING_APPROVE));
        return "approveaccount";
    }

    /**
     * status=0 通过 status=1 不通过
     *    进行审批 后重新
     *    获取 未通过审批的员工列表 添加数据到emps供前端调用
     * return 注册审批页面
     * */
    @RequestMapping("updatestatus")
    public String updatestatus(Integer employeeid, Integer status,Model model) {
        Integer result = employeeService.updatestatus(employeeid, status);
        model.addAttribute("emps", employeeService.getAllEmpsByStatus(PENDING_APPROVE));
        return "approveaccount";
    }
}
